from base.layer import Layer
import numpy as np

class DenseLayer(Layer):
    def __init__(self, x_dim, y_dim):
        super().__init__()
        self.weights = np.random.randn(y_dim,x_dim)
        self.bias = np.random.randn(y_dim,1)

    def forward(self,x):
        self.x = x
        y = np.dot(self.weights,x) + self.bias
        return y

    def backward(self,y_grad,learning_rate):
        x_grad = np.dot(self.weights.T, y_grad)
        self.weights -= learning_rate * y_grad * self.x.T
        self.bias -= learning_rate * y_grad
        return x_grad